#ifndef __TwBillboard_H__
#define __TwBillboard_H__

#include "TwMovableObject.h"
#include "TwRenderable.h"
#include "TwArray.h"
#include "TwAxisAlignedBox.h"

class TwBillboard : public TwMovableObject, public TwRenderable
{
public:
	struct VERTEX
	{
		D3DXVECTOR3			pos;
		DWORD				color;
		D3DXVECTOR2			tex;

		static const DWORD	FVF =  D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1;
	};

public:
	TwBillboard();
	virtual ~TwBillboard();

	void setRectangle(float left, float top, float width, float height);
	void setColor(const D3DXCOLOR& top_left, const D3DXCOLOR& top_right, const D3DXCOLOR& bottom_left, const D3DXCOLOR& bottom_right);
	void setTextures(float left, float top, float right, float bottom);
	void setTexture(IDirect3DTexture9* texture);
	void setAlpha(float alpha);
	void setFixedYawAxis(bool fixed);

	void needupdate();

	virtual void update();
	virtual void render(TwCamera* camera, TimeValue t);

	virtual void _updateRenderQueue(TwRenderQueue* queue, TwCamera* cam);
	virtual float getSquaredViewDepth(TwCamera* cam) const;

	virtual const TwAxisAlignedBox& getBoundingBox();

protected:
	void _setTransform(TwCamera* camera);

protected:
	bool				mNeedUpdate;

	IDirect3DTexture9*	mTexture;
	TwArray<VERTEX>		mVertices;

	// Vertex
	float				mLeft;
	float				mTop;
	float				mWidth;
	float				mHeight;

	// Vertex Diffuse
	ColorValue			mTopLeftColor;
	ColorValue			mTopRightColor;
	ColorValue			mBottomLeftColor;
	ColorValue			mBottomRightColor;

	// Texture coordinate
	float				mTexLeft;
	float				mTexTop;
	float				mTexRight;
	float				mTexBottom;

	bool				mYawFixed;

	TwAxisAlignedBox	mAABB;
};

#endif //__TwBillboard_H__